//
// Created by User on 24-10-5.
//

#ifndef VIDEO_CONFIG_HPP
#define VIDEO_CONFIG_HPP

#include <string>
#include <utility>

namespace utils
{
    class video_config final
    {
    public:
        enum class bit_control
        {
            VBR,
            CBR
        };

    public:
        ~video_config() = default;

        video_config(const video_config&) = default;

        video_config(video_config&&) = default;

        video_config& operator=(const video_config&) = default;

        video_config& operator=(video_config&&) = default;

    public:
        static video_config copy_stream()
        {
            video_config config;
            config.is_copy_stream = true;
            return config;
        }

        static video_config vbr_config(const std::string& encoder,
                                       const std::string& _profile, const std::string& level, const std::string& preset,
                                       int width, int height, int framerate,
                                       int bitrate, int max_bitrate, int min_bitrate)
        {
            return set_config(encoder, _profile, level, preset, bit_control::VBR,
                              width, height, framerate, bitrate,
                              max_bitrate, min_bitrate);
        }

        static video_config cbr_config(const std::string& encoder,
                                       const std::string& _profile, const std::string& level, const std::string& preset,
                                       int width, int height, int framerate, int bitrate)
        {
            return set_config(encoder, _profile, level, preset, bit_control::CBR, width, height, framerate, bitrate,
                              bitrate, bitrate);
        }

        bool is_copy() const
        {
            return is_copy_stream;
        }

        const std::string& get_profile() const
        {
            return m_profile;
        }

        bit_control get_bit_control() const
        {
            return m_bit_control;
        }

        int get_width() const
        {
            return m_width;
        }

        const std::string& get_level() const
        {
            return this->m_level;
        }

        const std::string& get_preset() const
        {
            return this->m_preset;
        }

        int get_height() const
        {
            return m_height;
        }

        int get_bitrate() const
        {
            return m_bitrate;
        }

        int get_max_bitrate() const
        {
            return m_max_bitrate;
        }

        int get_min_bitrate() const
        {
            return m_min_bitrate;
        }

        int get_framerate() const
        {
            return m_framerate;
        }

        const std::string& get_encoder() const { return this->encoder; }

    private:
        video_config() = default;

        static video_config set_config(
                const std::string& encoder,
                const std::string& _profile, const std::string& level, const std::string& preset,
                bit_control _bit_control,
                int width, int height, int framerate,
                int bitrate, int max_bitrate, int min_bitrate)
        {
            video_config config;
            config.encoder = encoder;
            config.is_copy_stream = false;
            config.m_bit_control = _bit_control;
            config.m_profile = _profile;
            config.m_preset = preset;
            config.m_level = level;
            config.m_width = width;
            config.m_height = height;
            config.m_framerate = framerate;
            config.m_bitrate = bitrate;
            config.m_max_bitrate = max_bitrate;
            config.m_min_bitrate = min_bitrate;
            return config;
        }

    private:
        bool is_copy_stream{};
        std::string encoder{};
        std::string m_profile{};
        std::string m_level{};
        std::string m_preset{};
        bit_control m_bit_control{bit_control::CBR};
        int m_width{};
        int m_height{};
        int m_bitrate{};
        int m_max_bitrate{};
        int m_min_bitrate{};
        int m_framerate{};
    };
}
#endif //VIDEO_CONFIG_HPP
